﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Tel_Mes_Interface
{
    public  class Mima
    {
        // MIMA
        private static string MidFiveMoveFront(string value)
        {
            string result;
            try
            {
                if (value.Length < 6)
                {
                    result = value;
                }
                else
                {
                    string text = "";
                    ArrayList arrayList = new ArrayList();
                    for (int i = 0; i < value.Length; i++)
                    {
                        arrayList.Add(value[i]);
                    }
                    text += arrayList[1];
                    text += arrayList[3];
                    text += arrayList[5];
                    text += arrayList[7];
                    text += arrayList[9];
                    arrayList.RemoveAt(1);
                    arrayList.RemoveAt(2);
                    arrayList.RemoveAt(3);
                    arrayList.RemoveAt(4);
                    arrayList.RemoveAt(5);
                    arrayList.Insert(0, text);
                    text = "";
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        text += arrayList[i];
                    }
                    result = text;
                }
            }
            catch
            {
                result = value;
            }
            return result;
        }

        // MIMA
        private static string FrontFiveMoveMid(string value)
        {
            string result;
            try
            {
                if (value.Length < 6)
                {
                    result = value;
                }
                else
                {
                    char[] array = new char[5];
                    array = value.Substring(0, 5).ToCharArray();
                    char[] array2 = new char[value.Length - 5];
                    array2 = value.Substring(5, value.Length - 5).ToCharArray();
                    char[] array3 = new char[value.Length];
                    array3[0] = array2[0];
                    array3[1] = array[0];
                    array3[2] = array2[1];
                    array3[3] = array[1];
                    array3[4] = array2[2];
                    array3[5] = array[2];
                    array3[6] = array2[3];
                    array3[7] = array[3];
                    array3[8] = array2[4];
                    array3[9] = array[4];
                    for (int i = 10; i < value.Length; i++)
                    {
                        array3[i] = array2[i - 5];
                    }
                    string text = "";
                    for (int i = 0; i < array3.Length; i++)
                    {
                        text += array3[i].ToString();
                    }
                    result = text.Trim();
                }
            }
            catch
            {
                result = value;
            }
            return result;
        }

        // MIMA
        private static string MovFan(string value, string key)
        {
            string result;
            try
            {
                if (value.Length < 6)
                {
                    result = value;
                }
                else
                {
                    char[] array = new char[key.Length];
                    array = key.ToCharArray();
                    int length = value.Length;
                    for (int i = array.Length - 1; i >= 0; i--)
                    {
                        int startIndex = Convert.ToInt32(array[i].ToString());
                        string value2 = value.Substring(length - 1, 1);
                        value = value.Remove(length - 1, 1);
                        value = value.Insert(startIndex, value2);
                    }
                    result = value;
                }
            }
            catch
            {
                result = value;
            }
            return result;
        }
        // MIMA
        private static string MovZhen(string value, string key)
        {
            string result;
            try
            {
                if (value.Length < 6)
                {
                    result = value;
                }
                else
                {
                    char[] array = new char[key.Length];
                    array = key.ToCharArray();
                    for (int i = 0; i < array.Length; i++)
                    {
                        int startIndex = Convert.ToInt32(array[i].ToString());
                        string str = value.Substring(startIndex, 1);
                        value = value.Remove(startIndex, 1);
                        value += str;
                    }
                    result = value;
                }
            }
            catch
            {
                result = value;
            }
            return result;
        }

        // MIMA
        public static string Jiami(string value, string key)
        {
            value = MovZhen(value, key);
            value = FrontFiveMoveMid(value);
            return value;
        }

        // MIMA
        public static string Jiemi(string value, string key)
        {
            value = MidFiveMoveFront(value);
            value = MovFan(value, key);
            return value;
        }

    }
}